﻿using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ymca.Entities;
using Ymca.Web.Models.Home;
using Ymca.Web.Resources;
using Ymca.Web.Services.Interfaces;

namespace Ymca.Web.Controllers
{
    public class HomeController : Controller
    {
		private IUnityContainer _container;
		private IContentValuesService _contentService;
		private string[] set = { "<p>", "</p>", "<br/>", " " };

		public HomeController()
		{
			_container = ContainerConfig.Container;
			_contentService = _container.Resolve<IContentValuesService>();
		}

		[HttpGet]
        public ActionResult Index()
        {
            return View();
        }

		[HttpGet]
		public ActionResult About()
		{
			ContentValue value = _contentService.GetValue("about");
			string about = value != null ? value.Value : string.Empty;
			ViewData["about"] = about;
			return View();
		}

		[HttpPost]
		[Authorize(Roles="Admin")]
		[ValidateInput(false)]
		public ActionResult About(string about)
		{
			if (ModelState.IsValid)
			{
				_contentService.SetValue("about", about);
			}
			return View();
		}

		[HttpGet]
		public ActionResult Contacts()
		{
			ContentValue value = _contentService.GetValue("contacts");
			string contacts = value != null ? value.Value : string.Empty;
			ViewData["contacts"] = contacts;
			return View();
		}

		[HttpPost]
		[Authorize(Roles = "Admin")]
		[ValidateInput(false)]
		public ActionResult Contacts(string contacts)
		{
			if (ModelState.IsValid)
			{
				_contentService.SetValue("contacts", contacts);
			}
			return View();
		}
    }
}
